<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Model\GoldCardLog;
use App\Model\UserWalletModel;
use Illuminate\Support\Facades\Log;

class EduReward extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'EduReward';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '教育奖分发';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //查出所有未分发的教育奖
        $all_golds = GoldCardLog::where('state',2)->get();
        foreach ($all_golds as $k=>$v)
        {
            Log::info("教育奖开始");
            //当前日期等于分奖日期 业绩大于一万的发奖
            if(date('Y-m-d',time()) == $v->jiesuan_time){
                if($v->all_yeji >= 10000){
                    /*
                    * uid 用户id
                    * sxj 奖金数额
                    * msg 描述
                    * type 1现金 2货款
                    * status 消费类型(type=1 1充值 2提现 3转货款 4成为VIP 5销售奖 6领导奖 7教育奖 8云仓库收益 9后台充值  type=2 3转货款 10入库 11下单 12创客奖 13累计充值够10000返利388)
                    * dy_table 对应表
                    * dy_id  报单用户id
                    */
                    UserWalletModel::handleAccount($v->uid,bcmul($v->all_yeji,$v->edu_rate,5),'+','教育奖',1,7,'',0);
                    //将处理完的订单更改状态
                    GoldCardLog::where('id',$v->id)->update(['state'=>1]);
                }else{
                    //分奖日期到了,业绩未大于一万处理为未完成
                    GoldCardLog::where('id',$v->id)->update(['state'=>3]);
                }
            }

        }
        Log::info("教育奖结束");

    }
}
